package com.yash.rms.filter;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper;

public class AuthenticationSuccessHandlerImpl extends
SimpleUrlAuthenticationSuccessHandler {

	@Override
	public void onAuthenticationSuccess(HttpServletRequest req,
			HttpServletResponse res, Authentication aut) throws IOException,
			ServletException {
		SecurityContextHolderAwareRequestWrapper sc = new SecurityContextHolderAwareRequestWrapper(req,"");
		
		if (aut != null) {
				if(sc.isUserInRole("ROLE_ADMIN"))setDefaultTargetUrl("/");
				else if(sc.isUserInRole("ROLE_USER"))setDefaultTargetUrl("/useractivitys");
		        super.onAuthenticationSuccess(req, res, aut);
		  }

	}

}
